<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>医疗器械不良事件上报修改表</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
</head>
<body>

<button type="button" class="layui-btn"  id = “back” onclick="self.location = document.referrer;">返回</button>
<form class="layui-form" lay-filter="FormLoad">
  <table border="1px" width="100%" cellpadding="0">
    <tr >
      <td colspan="4" style="text-align: center; height: 50px"> <span style=" font-size: 20px">医疗器械不良事件报告表</span> </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          报告日期：
        </td>
        <td colspan="1">
          <input type="text" name="report_date" placeholder="" class="layui-input">
        </td>

        <td>
          报告来源：
        </td>

        <td colspan="1">
          <input type="text" name="report_source" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          报告人：
        </td>
        <td colspan="1">
          <input type="text" name="reporter" placeholder="" class="layui-input">
        </td>

        <td>
          科室名称：
        </td>

        <td colspan="1">
          <input type="text" name="reporter_department" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <td colspan="4" style="height: 50px; text-align: center" >
        患者资料
      </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          姓名:
        </td>
        <td>
          <input type="text" name="patient_name" placeholder="" class="layui-input">
        </td>

        <td>
          年龄
        </td>

        <td>
          <input type="text" name="patient_age" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          性别：
        </td>
        <td colspan="1">

          <select name="patient_sex" lay-verify="required">
            <option value=""></option>
            <option value="男">男</option>
            <option value="女">女</option>
          </select>
        </td>
        <td>
        </td>
        <td>
        </td>

      </div>
    </tr>
    </tr>
    <div class="layui-form-item">
      <td>
        预期治疗疾病或作用
      </td>
      <td colspan="3">
        <textarea name="expect_treat_affect" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
      </td>
    </div>
    </tr>
    <tr>
      <td colspan="4" style="height: 50px; text-align: center" >
        不良事件情况
      </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1" >
          出现不良反应医疗器械品牌
        </td>
        <td colspan="1">
          <input type="text" name="apparatus_brand" placeholder="" class="layui-input">
        </td>
        <td>
          出现不良反应医疗器械名称
        </td>
        <td colspan="1">
          <input type="text" name="apparatus_name" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td>
          出现不良反应医疗器械批号
        </td>
        <td colspan="1">
          <input type="text" name="apparatus_num" placeholder="" class="layui-input">
        </td>
        <td></td> <td></td>
      </div>
    </tr>
    <div class="layui-form-item">
      <td>
        事件主要陈述及表现
      </td>
      <td colspan="3">
        <textarea name="bad_event_main_declare" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
      </td>
    </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          事件发生日期
        </td>
        <td colspan="1">
          <input type="text" name="event_happen_time" autocomplete="off" id="event_happen_time" class="layui-input">
        </td>
        <td colspan="1">
          发生或者知悉时间
        </td>
        <td colspan="1">
          <input type="text" name="reporter_know_time" autocomplete="off" id="reporter_know_time" class="layui-input">
        </td>
      </div>
    </tr>
    <tr style="font-size: 20px">
      <div class="layui-form-item">
        <td colspan="1"> 事件后果及处理措施
        </td>
        <td colspan="3">
          <textarea name="bad_event_ending" style="height: 120px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
        </td>
      </div>
    </tr>
    <tr>
      <td colspan="4">
        （外科治疗避免上述永久损伤: 可能导致机体功能机构永久性损伤： 机体功能机构永久性损伤：至少包括器械使用时间，使用目的，使用依据，使用情况，出现的不良时间情况，对受害者影响。采取的治疗措施，器械联合使用情况）
      </td>
    </tr>
  </table>
  <div class="layui-form-item">
    <div class="layui-input-block" style="text-align: center; margin-top: 50px">
      <button class="layui-btn" lay-submit lay-filter="save1">暂存</button>
      <button class="layui-btn" lay-submit lay-filter="save2">提交</button>
    </div>
  </div>
</form>

</body>

<script>

  let str;
  layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
    let $ = layui.jquery;
    let form = layui.form;
    let laydate = layui.laydate;
    var layer = layui.layer;
    var router = layui.router();
    laydate.render({
      elem: '#reporter_know_time' //指定元素
      , type: 'date'
    });
    laydate.render({
      elem: '#event_happen_time' //指定元素
      , type: 'date'
    });

    function getQueryVariable(variable)
    {
      let query = window.location.search.substring(1);
      let vars = query.split("&");
      for (let i=0;i<vars.length;i++) {
        let pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
      }
      return(false);
    }

    form.render();
    // 获取地址的中的值
    let form_code=getQueryVariable("form_code");
    console.log(form_code);
    $.ajax({
      url: '/look?form_code=' + form_code,
      type: 'get',
      success: function (data) {
        //console.log(data);
        let jsonObj = eval('(' + data + ')'); //获得jsonObj对象
        //console.log(jsonObj);
        //渲染 上报人和上报人单位
        let json = {};
        for(let i = 0; i<jsonObj.data.length; i++) {
          json[jsonObj.data[i].property_en_name] = jsonObj.data[i].detailed_data;
        }
        //console.log(json);
        form.val("FormLoad",json)
      }
    });

    form.on('submit(save1)', function (data) {
        layer.confirm('确定暂存吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
          let json = {
            "form_code": form_code,
            "reporter":data.field.reporter,
            "reporter_department":data.field.reporter_department,
            "patient_name":data.field.patient_name,
            "patient_age":data.field.patient_age,
            "patient_sex":data.field.patient_sex,
            "expect_treat_affect":data.field.expect_treat_affect,
            "apparatus_brand":data.field.apparatus_brand,
            "apparatus_name":data.field.apparatus_name,
            "apparatus_num":data.field.apparatus_num,
            "bad_event_main_declare":data.field.bad_event_main_declare,
            "event_happen_time":data.field.event_happen_time,
            "reporter_know_time":data.field.reporter_know_time,
            "bad_event_ending":data.field.bad_event_ending,
            "status":1 //暂存
          };

          $.ajax({
            url: '/event/event_update',
            type: "POST",
            data: json,
            success: function (index) {
              layer.msg("修改成功");
              self.location = document.referrer;
            }
          })

        }, function () {
          self.location = document.referrer;
        });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    form.on('submit(save2)', function (data) {

        layer.confirm('确定提交吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            let json = {
              "form_code": form_code,
              "reporter":data.field.reporter,
              "reporter_department":data.field.reporter_department,
              "patient_name":data.field.patient_name,
              "patient_age":data.field.patient_age,
              "patient_sex":data.field.patient_sex,
              "expect_treat_affect":data.field.expect_treat_affect,
              "apparatus_brand":data.field.apparatus_brand,
              "apparatus_name":data.field.apparatus_name,
              "apparatus_num":data.field.apparatus_num,
              "bad_event_main_declare":data.field.bad_event_main_declare,
              "event_happen_time":data.field.event_happen_time,
              "reporter_know_time":data.field.reporter_know_time,
              "bad_event_ending":data.field.bad_event_ending,
              "status":2 //递交
            };
            console.log(json);
            console.log("123");

            $.ajax({
                url: '/event/event_update',
                type: "POST",
                data: json,
                success: function (index) {
                  layer.msg("修改成功");
                  self.location = document.referrer;
                }
            })

        }, function () {
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

  })
</script>

</html>